<template>
  <div class="play-progress">
    <div class="time-line" @touchmove="moving" @touchend = "moveEnd">
      <div class="tl-finished" :style="{width: progress*100 + '%'}">
        <div class="tl-circle" @touchstart="moveStart"></div>
      </div>
    </div>
  </div>
</template>



<script>
export default {
  data() {
    return {
      progress: 0,
      flag: false
    };
  },
  methods: {
      moveStart(){
          this.flag = true;
      },
      moving(event){
          if(this.flag){
              let posX = event.changedTouches[0].clientX;
              let rw_total = event.currentTarget.clientWidth;
              let rw_left = event.currentTarget.offsetLeft;
              let pro = ((posX - rw_left) / rw_total );
              if (pro > 0.99) {
                  pro = 0.99;
              } else if (pro < 0.01) {
                  pro = 0;
              }
              this.progress = pro;
          }
      },
      moveEnd(){
          this.flag = false;
      }
  },
};
</script>

<style lang="scss" scoped>
.play-progress {
  width: 100%;
  height: 65px;
  background-color: rgba($color: #ffffff, $alpha: 0.15);
  position: relative;
  .time-line {
    height: 100%;
    margin: 0 auto;
    width: 80%;
    position: relative;
    .tl-finished {
      width: 20%;
      height: 2px;
      background-color: #eeeeee;
      position: absolute;
      top: 30px;
      left: 0;
      .tl-circle {
        position: absolute;
        top: -4px;
        right: 0px;
        width: 10px;
        border-radius: 50%;
        height: 10px;
        background-color: red;
        position: absolute;
      }
    }
  }
}
</style>
